home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 February / OpenLinux 2.3 CD.iso / live / bin / rpminst < prev    next >
Encoding:
Text File  |  1998-11-26  |  2.3 KB  |  146 lines

  1. #! /bin/bash
  2. # $Id: rpminst,v 1.10 1998/11/26 10:41:41 ray Exp $
  3. # full fledged bash version (requires perl also!)
  4. # (external: rpmextr, cpio, sleep + perl)
  5. C=$0; C=${C##*/}
  6.  
  7. DOIT=
  8. CpioP=
  9. All=true
  10. Verbose=false
  11. Vlevel=0
  12. Debug=false
  13. Dlevel=0
  14.  
  15. Usage() {
  16.   echo "Usage: $C [--force] [--verbose] [--spec] package.rpm ..." 1>&2
  17.   exit 1
  18. }
  19. true() {
  20.   return 0
  21. }
  22. false() {
  23.   return 1
  24. }
  25.  
  26. while [ $# -gt 0 ]; do
  27.   case "X$1" in
  28.    X--test|X-n)
  29.     DOIT=echo
  30.     shift
  31.     ;;
  32.    X--force|X-f)
  33.     Cpio=${Cpio}u
  34.     shift 
  35.     ;;
  36.   X--debug)
  37.     Dlevel=$[ $Dlevel + 1 ]
  38.     shift
  39.     ;;
  40.   X--verbose|X-v)
  41.     Vlevel=$[ $Vlevel + 1 ]
  42.     shift
  43.     ;;
  44.   X--spec|X-s)
  45.     CpioP='*.spec' 
  46.     All=false
  47.     shift
  48.     ;;
  49.   X-*)
  50.     Usage
  51.     ;;
  52.   X*)
  53.     break
  54.     ;;
  55.   esac
  56. done
  57.  
  58. # try to prepend path to this script to $PATH to find matching version
  59. # of rpmextr
  60. ADD=$0; ADD=${ADD%/*}
  61. if [ -x $ADD/rpmextr ]; then
  62.   [ -n $(perl -e '($_)=@ARGV;/^[^\/]/&&print;' $ADD) ] &&
  63.     ADD=$(cd $ADD; pwd)
  64.   if [ -n $(perl -e '($_,$p)=@ARGV;/(^|:)$p(:|$)/&&print;' $PATH $ADD) ]; then
  65.     [ $Dlevel -gt 1 ] && echo "prepending '$ADD' to PATH"
  66.     PATH=$ADD:$PATH
  67.     export PATH
  68.   fi
  69. fi
  70.  
  71. [ $Vlevel -ge 1 ] && Cpio=${Cpio}v
  72. [ $Vlevel -ge 2 ] && Verbose=true
  73.  
  74. #echo "C='$C'"
  75. case "$C" in
  76.  *inst*)
  77.   Inst=true
  78.   Cpio=dm$Cpio
  79.   ;;
  80.  *show*|*)
  81.   Inst=false
  82.   Cpio=tv
  83.   ;;
  84. esac
  85.  
  86. Process()
  87. {
  88.   local stage=$1
  89.   local file=$2
  90.   local name=$3
  91.   local run=$4
  92.   local script out
  93.  
  94.   $All || return 0
  95.  
  96.   out="%${stage}-${name}"
  97.   script=$(rpmextr --tag=$stage $file)
  98.  
  99.   echo "$out"
  100.   if [ -z "$script" ]; then
  101.     echo "--empty--"
  102.   else
  103.     if $run; then
  104.       echo "$script" | sh -x
  105.     elif $Inst; then
  106.       echo "$script"
  107.       echo "$script" > $out
  108.     else
  109.       echo "$script"
  110.     fi
  111.   fi
  112.   return $?
  113. }
  114.  
  115. Run=false
  116. if $Inst && $All && [ $(pwd) = "/" ]; then
  117.   echo "pre- and post-install scripts will be executed..."
  118.   sleep 4
  119.   Run=true
  120. fi
  121.  
  122. for P in "$@"; do
  123.   name=${P##*/}; name=${name%.i386.rpm}
  124.  
  125.   if [ ! -f "$P" ] || [ ! -r "$P" ]; then
  126.     echo "$C: can't read from '$P'! Skipped..." 1>&2
  127.     continue
  128.   fi
  129.  
  130.   $Verbose && echo "*** $P"
  131.   Process prein $P $name $Run
  132.  
  133.   $Verbose && echo "%files-${name}"
  134.  
  135.   [ -n "$CpioP" ] && set -f
  136.   set -- X $CpioP; shift
  137.  
  138.   rpmextr --cpio $P | cpio -i$Cpio "$@"
  139.  
  140.   [ -n "$CpioP" ] && set +f
  141.  
  142.   Process postin $P $name $Run
  143.  
  144. done
  145.  
  146.